using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace Liya.Crm.Data.Models.Mapping
{
    public class Sys_RoleUserMap : EntityTypeConfiguration<Sys_RoleUser>
    {
        public Sys_RoleUserMap()
        {
            // Primary Key
            this.HasKey(t => new { t.RUUserId, t.RURoleId });

            // Properties
            this.Property(t => t.RUUserId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.RURoleId)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.RUMemo)
                .HasMaxLength(200);

            // Table & Column Mappings
            this.ToTable("Sys_RoleUser");
            this.Property(t => t.RUUserId).HasColumnName("RUUserId");
            this.Property(t => t.RURoleId).HasColumnName("RURoleId");
            this.Property(t => t.RUMemo).HasColumnName("RUMemo");

            // Relationships
            this.HasRequired(t => t.Sys_Role)
                .WithMany(t => t.Sys_RoleUser)
                .HasForeignKey(d => d.RURoleId);
            this.HasRequired(t => t.Sys_UserInfo)
                .WithMany(t => t.Sys_RoleUser)
                .HasForeignKey(d => d.RUUserId);

        }
    }
}
